package com.example.diningcart.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.diningcart.mapper.ShoppingCartMapper;
import com.qf.pojos.ShoppingCart;
import com.qf.service.ShoppingCartService;
import org.apache.dubbo.config.annotation.Service;

import java.util.List;


@Service
public class ShoppingCartServiceImpl extends ServiceImpl<ShoppingCartMapper, ShoppingCart> implements ShoppingCartService {
    @Override
    public ShoppingCart getDishCartNumber(String dishId, String uid) {
        Wrapper cartQw = Wrappers.lambdaQuery(ShoppingCart.class)
        //定义sql语句只查询number列
        .select(ShoppingCart::getNumber)
        .eq(ShoppingCart::getDishId,dishId)
        .eq(ShoppingCart::getUserId,uid);

        return getBaseMapper().selectOne(cartQw);
    }

    @Override
    public List<ShoppingCart> listByUid(String uid) {
        Wrapper cartQw = Wrappers.lambdaQuery(ShoppingCart.class)
                //定义sql语句只查询number列
                .eq(ShoppingCart::getUserId,uid);
        return list(cartQw);
    }

    @Override
    public void removeByUid(String uid) {
        Wrapper cartQw = Wrappers.lambdaQuery(ShoppingCart.class)
                //定义sql语句只查询number列
                .eq(ShoppingCart::getUserId,uid);
        remove(cartQw);
    }
}
